﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommonComponent;
using MOD;
using BLL;

/// <summary>
/// 公告管理的展现层
/// </summary>
public class EBulletin
{
    BBulletin bBullectin = new BBulletin();
    /// <summary>
    /// 构造函数
    /// </summary>
    public EBulletin()
    {
    }

    /// <summary>
    /// 新建一条公告
    /// </summary>
    /// <param name="user">用户对象</param>
    /// <param name="bulletin_code">公告编号</param>
    /// <param name="bulletin_title">公告标题</param>
    /// <param name="bulletin_content">公告内容</param>
    /// <param name="issue_organ">发布部门</param>
    /// <returns></returns>
    public int CreateBulletin(User user,string bulletin_code, string bulletin_title,
           string bulletin_content, string bulletin_expiry_date)
    {
        OaBulletin bulletin = new OaBulletin();
        bulletin.BulletinCode = bulletin_code;
        bulletin.BulletinTitle = bulletin_title;
        bulletin.BulletinContent = bulletin_content;
        bulletin.IssueOrgan = user.Organ_code;
        bulletin.IssueEmpCode = user.Emp_code;
        bulletin.BulletinExpiryDate = Convert.ToDateTime(bulletin_expiry_date);
        DateTime dt = System.DateTime.Now;
        bulletin.IssueDatetime = dt;
        bulletin.LastUpdateEmp = user.Emp_code;
        bulletin.lastUpdateDatetime = dt;

        int result = 0;
        try
        {

            result =  bBullectin.CreateBulletin(bulletin);
        }
        catch (Exception ex)
        {
            CommonComponent.WebPage.JScript.JsAlert(ex.Message);
        }

        //附件上传未处理

        return result;
    }

    /// <summary>
    /// 公告管理主页面加载处理
    /// </summary>
    /// <returns>DataSet</returns>
    public DataSet PageLoadBulletin()
    {
        DataSet ds = null;
        try
        {

            ds = bBullectin.PageLoadBulletin();
        }
        catch (Exception ex)
        {
            CommonComponent.WebPage.JScript.JsAlert(ex.Message);
        }
        return ds;
    }

    /// <summary>
    /// 删除一条公告信息
    /// </summary>
    /// <param name="id">主键</param>
    /// <returns>true:成功;false:失败</returns>
    public bool DeleteBulletin(string pkId)
    {
        OaBulletin bulletin = new OaBulletin();
        bulletin.PkId = pkId;

        int result = 0;
        try
        {
            result = bBullectin.DeleteBulletin(bulletin);
            if (result > 0)
            {
                return true;
            }
        }
        catch(Exception ex)
        {
            CommonComponent.WebPage.JScript.JsAlert(ex.Message);
        }
        return false;
    }

    /// <summary>
    /// 更新数据库操作
    /// </summary>
    /// <param name="pkid">数据表主键PKID</param>
    /// <returns>true:成功;false:失败</returns>
    public int UpdateBulletin(string pkid, User user, string bulletin_code, string bulletin_title,
           string bulletin_content, string bulletin_expiry_date)
    {
        OaBulletin bulletin = new OaBulletin();
        bulletin.PkId = pkid;

        bulletin.BulletinCode = bulletin_code;
        bulletin.BulletinTitle = bulletin_title;
        bulletin.BulletinSubTitleTitle = "";
        bulletin.BulletinContent = bulletin_content;
        bulletin.LastUpdateEmp = user.Emp_code;
        bulletin.BulletinExpiryDate = CommonComponent.Common.TimeConvert.StringToDateTime(bulletin_expiry_date, "yyyy-M-d");
        bulletin.lastUpdateDatetime = System.DateTime.Now;

        int result = 0;
        try
        {
            result = bBullectin.UpdateBulletin(bulletin);
        }
        catch (Exception ex)
        {
            CommonComponent.WebPage.JScript.JsAlert(ex.Message);
        }
        return result;
    }

    /// <summary>
    /// 获取一条公告信息
    /// </summary>
    /// <param name="pkid">数据表主键PKID</param>
    /// <returns>公告对象</returns>
    public OaBulletin GetBulletinInfo(string pkid)
    {
        OaBulletin bulletin = new OaBulletin();
        bulletin.PkId = pkid;
        try
        {
            bulletin = bBullectin.GetBulletinInfo(pkid);
        }
        catch (Exception ex)
        {
            CommonComponent.WebPage.JScript.JsAlert(ex.Message);
        }
        return bulletin;
    }
}
